//
//  BasicView.m
//  TestMutableView
//
//  Created by Mirko on 15/12/17.
//  Copyright (c) 2015年 Mirko. All rights reserved.
//

#import "MCBasicView.h"

@implementation MCBasicView

+(MCBasicView *) loadIBView
{
    return [MCBasicView loadViewWithID:0 className:NSStringFromClass([self class])bundle:nil];
}

+(MCBasicView *) loadMCIBView
{
    return [MCBasicView loadViewWithID:0 className:NSStringFromClass([self class]) bundle:[MCUtils MCPMBundle]];
}

+(MCBasicView *) loadViewWithID:(NSInteger) viewId className:(NSString *) className bundle:(NSBundle *) bundle
{
    MCBasicView *resultView = nil;
    
    if (bundle) {
        resultView = [bundle loadNibNamed:className owner:nil options:nil][viewId];
    }
    else
    {
        if (!className || className.length == 0 || [className isEqualToString:@"MCBasicView"]) {
            return nil;
        }
        resultView = [[NSBundle mainBundle] loadNibNamed:className owner:nil options:nil][viewId];
    }
    return resultView;
}

+(MCBasicView *) loadIBViewWithType:(EViewType) type;
{
    return [MCBasicView loadViewWithID:type className:NSStringFromClass([self class]) bundle:nil];
}

+(MCBasicView *) loadMCIBViewWithType:(EViewType) type
{
    return [MCBasicView loadViewWithID:type className:NSStringFromClass([self class]) bundle:[MCUtils MCPMBundle]];
}

-(void) awakeFromNib
{
    [super awakeFromNib];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGestureAction:)];
    tap.cancelsTouchesInView = NO;
    [self addGestureRecognizer:tap];
}

-(void) handleTapGestureAction:(UITapGestureRecognizer *) gesture
{
    for (UIView *subView in self.subviews) {
        CGPoint touchPoint = [gesture locationInView:self];
        if (CGRectContainsPoint(subView.frame, touchPoint)) {
            return;
        }
    }
    [self tapNonEventArea];
    
    
}

-(void) tapNonEventArea
{
    
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
